// Package consts
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2023 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
package consts

import (
	"hotgo/internal/library/dict"
	"hotgo/internal/model"
)

func init() {
	dict.RegisterEnums("orderType", "订单类型", OrderTypeOptions)
	dict.RegisterEnums("orderStatus", "订单状态", UserOrderStatusOptions)
	dict.RegisterEnums("acceptRefundStatus", "订单退款受理状态", OrderAcceptRefundOptions)
}

// 订单分组
// 为不同的业务订单设置不同的分组，分组可以设置不同的业务回调方法

const (
	OrderGroupDefault    = "order"       // 普通订单
	OrderGroupAdminOrder = "admin_order" // 后台充值订单
	OrderGroupTransfer   = "transfer"    // 商家转账
	// 还可以设置其他，方便后期扩展..
)

// 订单类型

const (
	OrderTypeBalance = "balance" // 余额充值
	OrderTypeProduct = "product" // 购买产品
)

const (
	OrderStatusALL           = -1 // 全部状态
	OrderStatusNotPay        = 1  // 待付款
	OrderStatusPay           = 2  // 已付款
	OrderStatusDone          = 4  // 已完成
	OrderStatusClose         = 5  // 已关闭
	OrderStatusReturnRequest = 6  // 申请退款
	OrderStatusReturning     = 7  // 退款中
	OrderStatusReturned      = 8  // 已退款
	OrderStatusReturnReject  = 9  // 拒绝退款

	OrderStatusExpressed  = 10 // 已发货
	OrderStatusWaitVerify = 11 // 待核销
	OrderStatusVerified   = 12 // 已核销
)

// OrderStatusOptions 订单状态选项
var OrderStatusOptions = []*model.Option{
	dict.GenInfoOption(OrderStatusALL, "全部"),
	dict.GenDefaultOption(OrderStatusNotPay, "待付款"),
	dict.GenInfoOption(OrderStatusPay, "已付款"),
	dict.GenSuccessOption(OrderStatusDone, "已完成"),
	dict.GenDefaultOption(OrderStatusClose, "已关闭"),
	dict.GenWarningOption(OrderStatusReturnRequest, "申请退款"),
	dict.GenDefaultOption(OrderStatusReturning, "退款中"),
	dict.GenErrorOption(OrderStatusReturned, "已退款"),
	dict.GenWarningOption(OrderStatusReturnReject, "拒绝退款"),
	dict.GenInfoOption(OrderStatusExpressed, "已发货"),
	dict.GenInfoOption(OrderStatusWaitVerify, "待核销"),
	dict.GenSuccessOption(OrderStatusVerified, "已核销"),
}

// OrderAcceptRefundOptions 订单退款受理状态
var OrderAcceptRefundOptions = []*model.Option{
	dict.GenWarningOption(OrderStatusReturnRequest, "申请退款"),
	dict.GenSuccessOption(OrderStatusReturned, "已退款"),
	dict.GenErrorOption(OrderStatusReturnReject, "拒绝退款"),
}

// UserOrderStatusOptions 用户订单状态选项
const (
	UserOrderStatusAll           = "全部"
	UserOrderStatusNot           = "待付款"
	UserOrderStatusPay           = "已付款"
	UserOrderStatusWaitExpress   = "待发货"
	UserOrderStatusDone          = "已完成"
	UserOrderStatusClose         = "已关闭"
	UserOrderStatusReturnRequest = "申请退款"
	UserOrderStatusReturning     = "退款中"
	UserOrderStatusReturned      = "已退款"
	UserOrderStatusReturnReject  = "拒绝退款"

	UserOrderStatusExpressed  = "已发货"
	UserOrderStatusWaitVerify = "待核销"
	UserOrderStatusVerified   = "已核销"
)

var UserOrderStatusOptions = []*model.Option{
	dict.GenInfoOption(UserOrderStatusAll, "全部"),
	dict.GenInfoOption(UserOrderStatusNot, "待付款"),
	dict.GenInfoOption(UserOrderStatusPay, "已付款"),
	dict.GenWarningOption(UserOrderStatusWaitExpress, "待发货"),
	dict.GenSuccessOption(UserOrderStatusDone, "已完成"),
	dict.GenDefaultOption(UserOrderStatusClose, "已关闭"),
	dict.GenWarningOption(UserOrderStatusReturnRequest, "申请退款"),
	dict.GenDefaultOption(UserOrderStatusReturning, "退款中"),
	dict.GenErrorOption(UserOrderStatusReturned, "已退款"),
	dict.GenWarningOption(UserOrderStatusReturnReject, "拒绝退款"),

	dict.GenSuccessOption(UserOrderStatusExpressed, "已发货"),
	dict.GenWarningOption(UserOrderStatusWaitVerify, "待核销"),
	dict.GenSuccessOption(UserOrderStatusVerified, "已核销"),
}

const (
	OrderTypePointRight     = "积分权益" // 积分权益
	OrderTypePointECommerce = "积分电商" // 积分电商
	OrderTypeGroupOrder     = "团购订单" // 团购订单
	OrderTypeMemberOrder    = "会员订单" // 会员订单
)

var OrderTypeOptions = []*model.Option{
	dict.GenSuccessOption(OrderTypePointRight, "积分权益"),
	dict.GenWarningOption(OrderTypePointECommerce, "积分电商"),
	dict.GenInfoOption(OrderTypeGroupOrder, "团购订单"),
	dict.GenErrorOption(OrderTypeMemberOrder, "会员订单"),
}

// 包含已付款的状态
var UserOrderStatusPayStatus = []string{
	UserOrderStatusDone,
	UserOrderStatusPay,
	UserOrderStatusWaitExpress,
	UserOrderStatusWaitVerify,
	UserOrderStatusExpressed,
	UserOrderStatusReturnRequest,
	UserOrderStatusReturning,
	UserOrderStatusVerified,
}

func GetOrderTypeByProductScene(scene int) string {
	switch scene {
	case 1:
		return OrderTypePointRight
	case 2:
		return OrderTypePointECommerce
	case 3:
		return OrderTypeGroupOrder
	case 4:
		return OrderTypeMemberOrder
	default:
		return "未知类型"
	}
}

func GetOrderStatusByProductScene(scene int) string {
	switch scene {
	case -1:
		return UserOrderStatusAll
	case 1:
		return UserOrderStatusNot
	case 2:
		return UserOrderStatusPay
	case 3:
		return UserOrderStatusWaitExpress
	case 4:
		return UserOrderStatusDone
	case 5:
		return UserOrderStatusClose
	case 6:
		return UserOrderStatusReturnRequest
	case 7:
		return UserOrderStatusReturning
	case 8:
		return UserOrderStatusReturned
	case 9:
		return UserOrderStatusReturnReject
	case 10:
		return UserOrderStatusExpressed
	case 11:
		return UserOrderStatusWaitVerify
	case 12:
		return UserOrderStatusVerified
	default:
		return "未知状态"
	}
}

const (
	// 事件名常量
	NotToPayEvent                    = "NotToPayEvent"                    // 从Not到Pay状态的事件
	NotToCloseEvent                  = "NotToCloseEvent"                  // 从Not到Close状态的事件
	PayToWaitExpressEvent            = "PayToWaitExpressEvent"            // 从Pay到WaitExpress状态的事件
	PayToWaitVerifyEvent             = "PayToWaitVerifyEvent"             // 从Pay到WaitVerify状态的事件
	PayToReturnRequestEvent          = "PayToReturnRequestEvent"          // 从Pay到ReturnRequest状态的事件
	PayToDoneEvent                   = "PayToDoneEvent"                   // 从Pay到Done状态的事件
	WaitExpressToExpressedEvent      = "WaitExpressToExpressedEvent"      // 从WaitExpress到Expressed状态的事件
	WaitExpressToReturnRequestEvent  = "WaitExpressToReturnRequestEvent"  // 从WaitExpress到ReturnRequest状态的事件
	WaitVerifyToVerifiedEvent        = "WaitVerifyToVerifiedEvent"        // 从WaitVerify到Verified状态的事件
	WaitVerifyToReturnRequestEvent   = "WaitVerifyToReturnRequestEvent"   // 从WaitVerify到ReturnRequest状态的事件
	WaitVerifyToCloseEvent           = "WaitVerifyToCloseEvent"           // 从WaitVerify到Close状态的事件
	ExpressedToDoneEvent             = "ExpressedToDoneEvent"             // 从Expressed到Done状态的事件
	ExpressedToReturnRequestEvent    = "ExpressedToReturnRequestEvent"    // 从Expressed到ReturnRequest状态的事件
	VerifyToDoneEvent                = "VerifyToDoneEvent"                // 从Verify到Done状态的事件
	ReturnRequestToReturningEvent    = "ReturnRequestToReturningEvent"    // 从ReturnRequest到Returning状态的事件
	ReturnRequestToReturnRejectEvent = "ReturnRequestToReturnRejectEvent" // 从ReturnRequest到ReturnReject状态的事件
	ReturningToReturnedEvent         = "ReturningToReturnedEvent"         // 从Returning到Returned状态的事件
	ReturnedToCloseEvent             = "ReturnedToCloseEvent"             // 从Returned到Close状态的事件
)
